/**
 * Yolema.com Inc.
 * Copyright (c) 2011-2012 All Rights Reserved.
 */
package org.grayrabbit.pay.core.biz.manager.init;

import java.util.List;

import org.grayrabbit.pay.chinapay.config.ChinaPayInfo;
import org.grayrabbit.pay.chinapnr.config.ChinapnrInfo;
import org.grayrabbit.pay.core.model.entity.system.AppSystem;
import org.grayrabbit.pay.core.model.entity.system.TradeTerminal;
import org.grayrabbit.pay.core.model.utils.AppSystemUtil;
import org.grayrabbit.pay.core.service.system.AppSystemService;
import org.grayrabbit.pay.core.service.system.TradeTerminalService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 初始化公共的资源
 * 
 * @author wy
 * @version $Id: InitResouces.java, v 0.1 2012-6-6 上午9:52:40 wy Exp $
 */
@Component
public class InitResouces implements InitializingBean {

    private static final Logger  LOG = LoggerFactory.getLogger(InitResouces.class);

    @Autowired
    private AppSystemService     appSystemService;

    @Autowired
    private TradeTerminalService tradeTerminalService;

    @Override
    public void afterPropertiesSet() throws Exception {
        LOG.info("初始化系统相关信息.....");
        initAppSystem();
        initPay();
    }

    private void initAppSystem() {
        //初始化应用系统
        List<AppSystem> appSystemList = appSystemService.findAll();
        AppSystemUtil.putAllAppSystem(appSystemList);
    }

    private void initPay() {
        //初始化银联交易配置信息
        TradeTerminal chinapayTerminal = tradeTerminalService
            .getByTerminalCode(ChinaPayInfo.CHINAPAY_CODE);
        if (chinapayTerminal == null) {
            LOG.error("从数据库获取不到对应的银联信息..");
        } 
        
        TradeTerminal chinapnrTerminal = tradeTerminalService
                .getByTerminalCode(ChinapnrInfo.CHINAPNR_CODE);
        if (chinapnrTerminal == null) {
            LOG.error("从数据库获取不到对应的汇付信息..");
        } 
    }

}
